/*     */ package com.zimbra.cs.service.account;
/*     */ 
/*     */ import com.google.common.collect.Sets;
/*     */ import com.zimbra.common.account.ZAttrProvisioning.DistributionListSubscriptionPolicy;
/*     */ import com.zimbra.common.account.ZAttrProvisioning.DistributionListUnsubscriptionPolicy;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.soap.AccountConstants;
/*     */ import com.zimbra.common.soap.Element;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.Group;
/*     */ import com.zimbra.cs.account.Group.GroupOwner;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.account.accesscontrol.ACLUtil;
/*     */ import com.zimbra.cs.account.accesscontrol.GranteeType;
/*     */ import com.zimbra.cs.account.accesscontrol.Right;
/*     */ import com.zimbra.cs.account.accesscontrol.RightManager;
/*     */ import com.zimbra.cs.account.accesscontrol.ZimbraACE;
/*     */ import com.zimbra.soap.ZimbraSoapContext;
/*     */ import java.util.Collections;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import java.util.Map.Entry;
/*     */ import java.util.Set;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class GetDistributionList
/*     */   extends DistributionListDocumentHandler
/*     */ {
/*  42 */   private static final Set<String> OWNER_ATTRS = Sets.newHashSet(new String[] { "description", "displayName", "mail", "zimbraHideInGal", "zimbraIsAdminGroup", "zimbraLocale", "zimbraMailAlias", "zimbraMailStatus", "zimbraNotes", "zimbraPrefReplyToAddress", "zimbraPrefReplyToDisplay", "zimbraPrefReplyToEnabled", "zimbraDistributionListSubscriptionPolicy", "zimbraDistributionListUnsubscriptionPolicy" });
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*  58 */   private static final Set<String> NON_OWNER_ATTRS = Sets.newHashSet(new String[] { "description", "displayName", "zimbraHideInGal", "zimbraNotes", "zimbraDistributionListSubscriptionPolicy", "zimbraDistributionListUnsubscriptionPolicy" });
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public Element handle(Element request, Map<String, Object> context)
/*     */     throws ServiceException
/*     */   {
/*  69 */     ZimbraSoapContext zsc = getZimbraSoapContext(context);
/*  70 */     Provisioning prov = Provisioning.getInstance();
/*  71 */     Account acct = getAuthenticatedAccount(zsc);
/*     */     
/*  73 */     Element response = zsc.createElement(AccountConstants.GET_DISTRIBUTION_LIST_RESPONSE);
/*     */     
/*  75 */     Group group = getGroupBasic(request, prov);
/*  76 */     GetDistributionListHandler handler = new GetDistributionListHandler(group, request, response, prov, acct);
/*     */     
/*  78 */     handler.handle();
/*     */     
/*  80 */     return response;
/*     */   }
/*     */   
/*     */   private static class GetDistributionListHandler extends DistributionListDocumentHandler.SynchronizedGroupHandler
/*     */   {
/*     */     private Element request;
/*     */     private Element response;
/*     */     private Provisioning prov;
/*     */     private Account acct;
/*     */     
/*     */     protected GetDistributionListHandler(Group group, Element request, Element response, Provisioning prov, Account acct)
/*     */     {
/*  92 */       super();
/*  93 */       this.request = request;
/*  94 */       this.response = response;
/*  95 */       this.prov = prov;
/*  96 */       this.acct = acct;
/*     */     }
/*     */     
/*     */     protected void handleRequest() throws ServiceException
/*     */     {
/* 101 */       boolean isOwner = Group.GroupOwner.isOwner(this.acct, this.group);
/*     */       
/*     */ 
/* 104 */       boolean isMember = this.group.isMemberOf(this.acct);
/*     */       
/* 106 */       boolean needOwners = this.request.getAttributeBool("needOwners", false);
/*     */       
/*     */ 
/*     */ 
/* 110 */       Element eDL = com.zimbra.cs.service.admin.GetDistributionList.encodeDistributionList(this.response, this.group, true, !needOwners, false, null, null);
/*     */       
/*     */ 
/* 113 */       if (isMember) {
/* 114 */         eDL.addAttribute("isMember", true);
/*     */       }
/*     */       
/* 117 */       if (isOwner) {
/* 118 */         eDL.addAttribute("isOwner", true);
/*     */       }
/*     */       
/* 121 */       GetDistributionList.encodeAttrs(this.group, eDL, isOwner ? GetDistributionList.OWNER_ATTRS : GetDistributionList.NON_OWNER_ATTRS);
/*     */       
/* 123 */       if (isOwner) {
/* 124 */         encodeRights(eDL);
/*     */       }
/*     */     }
/*     */     
/*     */     private void encodeRights(Element eDL) throws ServiceException {
/* 129 */       String needRights = this.request.getAttribute("needRights", null);
/* 130 */       if (needRights == null) {
/* 131 */         return;
/*     */       }
/* 133 */       String[] rights = needRights.split(",");
/*     */       
/* 135 */       RightManager rightMgr = RightManager.getInstance();
/*     */       
/* 137 */       Element eRights = eDL.addElement("rights");
/* 138 */       Element eRight; for (String rightStr : rights) {
/* 139 */         Right right = rightMgr.getUserRight(rightStr);
/*     */         
/* 141 */         if (Group.GroupOwner.GROUP_OWNER_RIGHT == right) {
/* 142 */           throw ServiceException.INVALID_REQUEST(right.getName() + " cannot be queried directly, owners are returned in the" + " owners section", null);
/*     */         }
/*     */         
/*     */ 
/*     */ 
/* 147 */         eRight = eRights.addElement("right");
/* 148 */         eRight.addAttribute("right", right.getName());
/*     */         
/* 150 */         List<ZimbraACE> acl = ACLUtil.getACEs(this.group, Collections.singleton(right));
/* 151 */         if (acl != null) {
/* 152 */           for (ZimbraACE ace : acl) {
/* 153 */             Element eGrantee = eRight.addElement("grantee");
/* 154 */             eGrantee.addAttribute("type", ace.getGranteeType().getCode());
/* 155 */             eGrantee.addAttribute("id", ace.getGrantee());
/* 156 */             eGrantee.addAttribute("name", ace.getGranteeDisplayName());
/*     */           }
/*     */         }
/*     */       }
/*     */     }
/*     */   }
/*     */   
/*     */   public static void encodeAttrs(Group group, Element eParent, Set<String> specificAttrs) {
/* 164 */     Map<String, Object> attrsMap = group.getUnicodeAttrs();
/*     */     
/* 166 */     if ((specificAttrs == null) || (!specificAttrs.isEmpty())) {
/* 167 */       for (Map.Entry<String, Object> entry : attrsMap.entrySet()) {
/* 168 */         String key = (String)entry.getKey();
/*     */         
/* 170 */         if ((specificAttrs == null) || (specificAttrs.contains(key)))
/*     */         {
/*     */ 
/*     */ 
/* 174 */           if ((!key.equals("zimbraDistributionListSubscriptionPolicy")) && (!key.equals("zimbraDistributionListUnsubscriptionPolicy")))
/*     */           {
/*     */ 
/*     */ 
/*     */ 
/* 179 */             Object value = entry.getValue();
/* 180 */             if ((value instanceof String[])) {
/* 181 */               String[] sa = (String[])value;
/* 182 */               for (int i = 0; i < sa.length; i++) {
/* 183 */                 eParent.addKeyValuePair(key, sa[i], "a", "n");
/*     */               }
/*     */             } else {
/* 186 */               eParent.addKeyValuePair(key, (String)value, "a", "n");
/*     */             }
/*     */           }
/*     */         }
/*     */       }
/*     */     }
/* 192 */     if ((specificAttrs == null) || (specificAttrs.contains("zimbraDistributionListSubscriptionPolicy"))) {
/* 193 */       eParent.addKeyValuePair("zimbraDistributionListSubscriptionPolicy", group.getSubscriptionPolicy().name(), "a", "n");
/*     */     }
/*     */     
/*     */ 
/*     */ 
/* 198 */     if ((specificAttrs == null) || (specificAttrs.contains("zimbraDistributionListUnsubscriptionPolicy"))) {
/* 199 */       eParent.addKeyValuePair("zimbraDistributionListUnsubscriptionPolicy", group.getUnsubscriptionPolicy().name(), "a", "n");
/*     */     }
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   public static Set<String> visibleAttrs(Iterable<String> needAttrs, boolean isOwner)
/*     */   {
/* 207 */     Set<String> visibleAttrs = Sets.newHashSet();
/*     */     
/* 209 */     Set<String> allowedAttrs = isOwner ? OWNER_ATTRS : NON_OWNER_ATTRS;
/*     */     
/* 211 */     for (String attr : needAttrs) {
/* 212 */       if (allowedAttrs.contains(attr)) {
/* 213 */         visibleAttrs.add(attr);
/*     */       }
/*     */     }
/*     */     
/* 217 */     return visibleAttrs;
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/account/GetDistributionList.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */